
// 定义记分牌score-pane类
class ScorePanel {
    // score level  分数  等级
    score = 0;
    level = 1;
    // 分数和等级所在的元素，在构造函数中初始化
    scoreEle: HTMLElement;
    levelEle: HTMLElement;

    // 设置一个变量 限制等级
    maxLevel: number;
    // 设置多少分升级
    upScore: number
    constructor(maxLevel: number = 10, upScore: number = 2) {
        this.scoreEle = document.getElementById("score")!;
        this.levelEle = document.getElementById("level")!;
        this.maxLevel = maxLevel;
        this.upScore = upScore;
    }

    // 设置加分的方法

    addScore() {
        this.score++;
        this.scoreEle.innerHTML = this.score + '';
        // 判断分数 每10分升1级
        if (this.score % this.upScore === 0) {
            this.levelUp()
        }
    }
    // 设置等级提升的方法
    levelUp() {
        if (this.level < this.maxLevel) {
            this.level += 1;
            this.levelEle.innerHTML = this.level + '';
        }
    }
}

export default ScorePanel


